package cn.com.guage.dtm.mapping.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.mapping.domain.MappingFieldInfo;
import cn.com.guage.dtm.mapping.service.IMappingFieldInfoService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 字段级映射信息Controller
 * 
 * @author liujun
 * @date 2021-07-14
 */
@Controller
@RequestMapping("/mapping/field")
public class MappingFieldInfoController extends BaseController
{
    private String prefix = "mapping/field";

    @Autowired
    private IMappingFieldInfoService mappingFieldInfoService;

//    @RequiresPermissions("mapping:field:view")
//    @GetMapping()
//    public String field()
//    {
//        return prefix + "/field";
//    }
    
    @RequiresPermissions("mapping:field:view")
    @GetMapping("/{tableId}")
    public String fieldOfTable(@PathVariable("tableId") Long tableId, ModelMap mmap)
    {
    	mmap.put("tableId", tableId);
        return prefix + "/field";
    }

    /**
     * 查询字段级映射信息列表
     */
    @RequiresPermissions("mapping:field:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MappingFieldInfo mappingFieldInfo)
    {
        startPage();
        List<MappingFieldInfo> list = mappingFieldInfoService.selectMappingFieldInfoList(mappingFieldInfo);
        return getDataTable(list);
    }

    /**
     * 导出字段级映射信息列表
     */
    @RequiresPermissions("mapping:field:export")
    @Log(title = "字段级映射信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MappingFieldInfo mappingFieldInfo)
    {
        List<MappingFieldInfo> list = mappingFieldInfoService.selectMappingFieldInfoList(mappingFieldInfo);
        ExcelUtil<MappingFieldInfo> util = new ExcelUtil<MappingFieldInfo>(MappingFieldInfo.class);
        return util.exportExcel(list, "字段级映射信息数据");
    }

    /**
     * 新增字段级映射信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存字段级映射信息
     */
    @RequiresPermissions("mapping:field:add")
    @Log(title = "字段级映射信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MappingFieldInfo mappingFieldInfo)
    {
        return toAjax(mappingFieldInfoService.insertMappingFieldInfo(mappingFieldInfo));
    }

    /**
     * 修改字段级映射信息
     */
    @GetMapping("/edit/{fieldId}")
    public String edit(@PathVariable("fieldId") Long fieldId, ModelMap mmap)
    {
        MappingFieldInfo mappingFieldInfo = mappingFieldInfoService.selectMappingFieldInfoById(fieldId);
        mmap.put("mappingFieldInfo", mappingFieldInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存字段级映射信息
     */
    @RequiresPermissions("mapping:field:edit")
    @Log(title = "字段级映射信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MappingFieldInfo mappingFieldInfo)
    {
        return toAjax(mappingFieldInfoService.updateMappingFieldInfo(mappingFieldInfo));
    }

    /**
     * 删除字段级映射信息
     */
    @RequiresPermissions("mapping:field:remove")
    @Log(title = "字段级映射信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mappingFieldInfoService.deleteMappingFieldInfoByIds(ids));
    }
}
